<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class User extends CI_Controller {

	public function index()
	{

	}
	public function get_all_user()
	{
		$this->load->model('user_model');
		$data['user'] = $this->user_model->get_user();
	    $data['phone'] = 'user archive';
	    $this->load->view('list_user', $data);
		return;
	}
	public function get_userbyPhone()
	{
		$phone = $this->input->post('phone');
		if($phone=='') {
			$this->load->view('show_logo');
			return;
		}
		$this->load->model('user_model');
		$data['user'] = $this->user_model->get_user($phone);
		$data['phone'] = 'user archive';
	    $this->load->view('user_result', $data);	
	}
	public function modify_userbyPhone($sign=false){
		$this->load->helper('form');
	    $form = array(
	    	'class' => 'form', 
	    	'id' 	=> 'search');
	    echo form_open('user/modify_userbyPhone/ture',$form);
	    echo form_label('phone');
	    echo form_input('phone');
	    echo form_submit('search_btn', 'search!');
	    echo form_close(' ');
	    if($sign !== false){
			$phone = $this->input->post('phone');
			if($phone=='') {
				$this->load->view('show_logo');
				return;
			}
			$this->load->model('user_model');
			$data['user'] = $this->user_model->get_user($phone);
			$data['title'] = 'user archive';
		    $this->load->view('show_modify_user', $data);
		}	
	}
	
		public function modify_user()
	{
		$this->load->model('user_model');
		$userInfo = array(
		'id'		=> $this->input->post('id'),
		'name'		=> $this->input->post('name'),
		'point' 	=> $this->input->post('point'),
		'level'  	=> $this->input->post('level'),
		'email'		=> $this->input->post('email'),
		'phone'		=> $this->input->post('phone')
		);
		if($this->user_model->modify_user_info($userInfo)){
			$this->load->helper('form');
		    $form = array(
		    	'class' => 'form', 
		    	'id' 	=> 'search');
		    echo form_open('user/modify_userbyPhone/ture',$form);
		    echo form_input('phone');
		    echo form_submit('search_btn', 'search!');
	    	echo form_close(' ');
			$data['user'] = $this->user_model->get_user($userInfo['phone']);
			$this->load->view('show_modify_user',$data);
			return;
		}
		$data['msg']=$userInfo['id']+'fail';
		$this->load->view('unittest',$data);
		return;
	}
	public function show_logo()
	{
		$this->load->view('show_logo');
	}

}
